<%@ page language="java" import="java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="utf-8"%>
<html>
<head>
<link type="text/css" href="../css/global.css" rel="stylesheet" />
<link type="text/css" href="../css/simpletable.css" rel="stylesheet" />		


<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				$('#refreash').click(function() {
					//alert("refreash...");
                	$(location).attr('href',"index.jsp");
            	});
        
        var add = <%=request.getParameter("add")%>;
        //alert(add);
        if(add==null){
        	$('#detail').hide();
        }
        else{
        	
			$("#submit").hide();
			$("#CCParameterName").val("");
			$("#StorerkeyFrom").val("0");
			$("#StorerkeyTo").val("ZZZZZZZZZZ");
			$("#SkuFrom").val("0");
			$("#SkuTo").val("ZZZZZZZZZZ");
			$("#ClassFrom").val("0");
			$("#ClassTo").val("ZZZZZZZZZZ");
			$("#ZoneFrom").val("0");
			$("#ZoneTo").val("ZZZZZZZZZZ");
			$("#LocFrom").val("0");
			$("#LocTo").val("ZZZZZZZZZZ");
			$("#XCOORDFROM").val("0");
			$("#XCOORDTO").val("999999");
			$("#YCOORDFROM").val("0");
			$("#YCOORDTO").val("999999");
			$("#ZCOORDFROM").val("0");
			$("#ZCOORDTO").val("999999");
			
			$("#CCParameterName").attr("disabled", false);
			$("#StorerkeyFrom").attr("disabled", false);
			$("#StorerkeyTo").attr("disabled", false);
			$("#SkuFrom").attr("disabled", false);
			$("#SkuTo").attr("disabled", false);
			$("#ClassFrom").attr("disabled", false);
			$("#ClassTo").attr("disabled", false);
			$("#ZoneFrom").attr("disabled", false);
			$("#ZoneTo").attr("disabled", false);
			$("#LocFrom").attr("disabled", false);
			$("#LocTo").attr("disabled", false);
			$("#XCOORDFROM").attr("disabled", false);
			$("#XCOORDTO").attr("disabled", false);
			$("#YCOORDFROM").attr("disabled", false);
			$("#YCOORDTO").attr("disabled", false);
			$("#ZCOORDFROM").attr("disabled", false);
			$("#ZCOORDTO").attr("disabled", false);
			$("#DisplaySystemCount").attr('disabled', false);
        }
		$('#search').click(function() {
			alert("search");
			$.ajaxSetup({
				cache : false
			});
			$("#mytable").find("tr:gt(1)").remove();
			//$.getJSON("qservice.jsp", { Serailkey: $("input[name='Serailkey']:checked").val() }, function(data, state) {
			$.getJSON("servicec.jsp", {

				StorerkeyFromSearch : $("#StorerkeyFromSearch").val(),
				StorerkeyToSearch : $("#StorerkeyToSearch").val(),
				SkuFromSearch : $("#SkuFromSearch").val(),
				SkuToSearch : $("#SkuToSearch").val(),
				ClassFromSearch : $("#ClassFromSearch").val(),
				ClassToSearch : $("#ClassToSearch").val(),
				ZoneFromSearch : $("#ZoneFromSearch").val(),
				ZoneToSearch : $("#ZoneToSearch").val(),
				LocFromSearch : $("#LocFromSearch").val(),
				LocToSearch : $("#LocToSearch").val()

			}, function(data, state) {
				//alert(data);
				$.each(data.jsonChildarray, function(i, data) {
					alert(data.StorerkeyFrom + data.StorerkeyTo);
					$("#mytable").append(
							'<tr><td><input type="radio" name="Serailkey" value="' + data.Serailkey + '" /></td><td>' 
							+ data.StorerkeyFrom + '</td><td>' 
							+ data.StorerkeyTo + '</td><td>' 
							+ data.SkuFrom + '</td><td>' 
							+ data.SkuTo + '</td><td>' 
							+ data.ClassFrom + '</td><td>' 
							+ data.ClassTo + '</td><td>' 
							+ data.ZoneFrom + '</td><td>' 
							+ data.ZoneTo + '</td><td>' 
							+ data.LocFrom + '</td><td>' 
							+ data.LocTo + '</td>'
							+ '</tr>');
							});
							/******************/
								
			});
			
			return false;
		});

		$('#add').click(function() {
			$('#detail').show();
			$("#submit").hide();
			$("#CCParameterName").val("");
			$("#StorerkeyFrom").val("0");
			$("#StorerkeyTo").val("ZZZZZZZZZZ");
			$("#SkuFrom").val("0");
			$("#SkuTo").val("ZZZZZZZZZZ");
			$("#ClassFrom").val("0");
			$("#ClassTo").val("ZZZZZZZZZZ");
			$("#ZoneFrom").val("0");
			$("#ZoneTo").val("ZZZZZZZZZZ");
			$("#LocFrom").val("0");
			$("#LocTo").val("ZZZZZZZZZZ");
			$("#XCOORDFROM").val("0");
			$("#XCOORDTO").val("999999");
			$("#YCOORDFROM").val("0");
			$("#YCOORDTO").val("999999");
			$("#ZCOORDFROM").val("0");
			$("#ZCOORDTO").val("999999");
			
			$("#CCParameterName").attr("disabled", false);
			$("#StorerkeyFrom").attr("disabled", false);
			$("#StorerkeyTo").attr("disabled", false);
			$("#SkuFrom").attr("disabled", false);
			$("#SkuTo").attr("disabled", false);
			$("#ClassFrom").attr("disabled", false);
			$("#ClassTo").attr("disabled", false);
			$("#ZoneFrom").attr("disabled", false);
			$("#ZoneTo").attr("disabled", false);
			$("#LocFrom").attr("disabled", false);
			$("#LocTo").attr("disabled", false);
			$("#XCOORDFROM").attr("disabled", false);
			$("#XCOORDTO").attr("disabled", false);
			$("#YCOORDFROM").attr("disabled", false);
			$("#YCOORDTO").attr("disabled", false);
			$("#ZCOORDFROM").attr("disabled", false);
			$("#ZCOORDTO").attr("disabled", false);
			$("#DisplaySystemCount").attr('disabled', false);
			
			//alert("CC checked?");
			$("#CC").attr('checked', true);
			//alert("CC checked?" + $("#CC").val());
			//$("#CC").checked = true;
			//alert("CC checked?"+ $("#CC").val());

			//alert($("input[name='Serailkey']:checked").val());
			$("input[name='item']:checked").attr('checked', false);
			//alert($("input[name='Serailkey']:checked").val());
			//$("input[name='Serailkey']:checked").removeAttr("checked");
			return false;
		});

		//$('#Serailkey').change(function() {
		//$("input[@name='Serailkey']").change(function(){
		$(".detailImg").click(function() {
			//alert($("input[name='Serailkey']:checked").val());
			
			$('#Serailkey').val(this.id);
			$('#detail').show();
			$('#submit').show();
			$.ajaxSetup({
				cache : false
			});
			//$.getJSON("qservice.jsp", { Serailkey: $("input[name='Serailkey']:checked").val() }, function(data, state) {
			$.getJSON("query.jsp", {
				Serailkey : this.id
			}, function(data, state) {

				/*****************debug/
				alert("data: " + data.StorerkeyFrom);
				/******************/
 
				$("#CCParameterName").val(data.CCParameterName);
				$("#StorerkeyFrom").val(data.StorerkeyFrom);
				$("#StorerkeyTo").val(data.StorerkeyTo);
				$("#SkuFrom").val(data.SkuFrom);
				$("#SkuTo").val(data.SkuTo);
				$("#ClassFrom").val(data.ClassFrom);
				$("#ClassTo").val(data.ClassTo);
				$("#ZoneFrom").val(data.ZoneFrom);
				$("#ZoneTo").val(data.ZoneTo);
				$("#LocFrom").val(data.LocFrom);
				$("#LocTo").val(data.LocTo);
				$("#XCOORDFROM").val(data.XCOORDFROM);
				$("#XCOORDTO").val(data.XCOORDTO);
				$("#YCOORDFROM").val(data.YCOORDFROM);
				$("#YCOORDTO").val(data.YCOORDTO);
				$("#ZCOORDFROM").val(data.ZCOORDFROM);
				$("#ZCOORDTO").val(data.ZCOORDTO);
				
				
				$("#CCParameterName").attr("disabled", true);
				$("#StorerkeyFrom").attr("disabled", true);
				$("#StorerkeyTo").attr("disabled", true);
				$("#SkuFrom").attr("disabled", true);
				$("#SkuTo").attr("disabled", true);
				$("#ClassFrom").attr("disabled", true);
				$("#ClassTo").attr("disabled", true);
				$("#ZoneFrom").attr("disabled", true);
				$("#ZoneTo").attr("disabled", true);
				$("#LocFrom").attr("disabled", true);
				$("#LocTo").attr("disabled", true);
				$("#XCOORDFROM").attr("disabled", true);
				$("#XCOORDTO").attr("disabled", true);
				$("#YCOORDFROM").attr("disabled", true);
				$("#YCOORDTO").attr("disabled", true);
				$("#ZCOORDFROM").attr("disabled", true);
				$("#ZCOORDTO").attr("disabled", true);
				
				if (data.DisplaySystemCount == 1) {
					$("#DisplaySystemCount").attr('checked', true);
				} else {
					$("#DisplaySystemCount").attr('checked', false);
				}
				$("#DisplaySystemCount").attr('disabled', true);
				$("#CC").attr('checked', true);

				/******************/
				//if ( k == -1 ){}
			});
			return false;
		});
		

	});//$(document).ready	

	function add() {
		$("#myform").attr("action", "index.jsp?status=ok&add=1");
		$("#myform").submit();
	}
	function Search() {
		$("#myform").attr("action", "index.jsp?status=ok");
		$("#myform").submit();
	}
	function save() {
		$("#myform").attr("action", "save.jsp");
		$("#myform").submit();
	}
	function del() {
		$("#myform").attr("action", "del.jsp");
		$("#myform").submit();
	}


	function Go_Page(i){
		//alert($("#pages").val());
			$("#pages").val(i);
		//alert($("#pages").val());
		$("#myform").attr("action", "index.jsp?status=ok");
		$("#myform").submit();
	}
	
	function getURLParameter(name) {
		return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(
				Location.search) || [ , null ])[1]);
	}

	$.fn.clearForm = function() {
		// iterate each matching form
		return this.each(function() {
			// iterate the elements within the form
			$(':input', this).each(function() {
				var type = this.type, tag = this.tagName.toLowerCase();
				if (type == 'text' || type == 'password' || tag == 'textarea')
					this.value = '';
				else if (type == 'checkbox' || type == 'radio')
					this.checked = false;
				else if (tag == 'select')
					this.selectedIndex = -1;
			});
		});
	};
</script>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


<body>
<%
			String status = "";
			if("ok".equals(request.getParameter("status"))){
				String action = request.getParameter("action");
				if("save".equals(action)){
					status = "已成功保存";
				}
				if("del".equals(action)){
					status = "已成功刪除";
				}
				if("pub".equals(action)){
					status = "已成功發佈";
				}
			}
%>

	<form id='myform' action="updatetable.jsp" method="post" ALIGN="CENTER" >
		<table width="100%" class="gridBody">
			<tr>
			
			<div class="queryPanel">
			<div class="handleControl">
			
			
			
			<!-- <th Width="70"><input type="button" class="wmsButton" id="add" value="新增" /></th>-->
			<input type="button" style="width: 80px" class="wmsButton" onclick="add()" value="新增" />
			<input type="button" style="width: 80px" class="wmsButton" onclick="save()" value="保存" />
			<input type="button" style="width: 80px" class="wmsButton" onclick="del()" value="刪除" />
			<!-- <input type="button" class="wmsButton" id="refreash" value="刷新" /> -->
			
			<STRONG>目前頁數&nbsp;</STRONG>
			
			
			
			
			
			
			<% 
			
			int i;
			int ipage = 10; //分頁單位 
			int allpage; //總頁數 
			int pages; //接受的頁碼變數 
			int cpage = 1; //當前頁 
			int spage; //開始頁 
			int allCol = 0;
			
			java.lang.String pagesql0, pagesql;
			java.sql.ResultSet pagers0, pagers;
			Statement statement = null;
			
			Connection conn = null;
			PreparedStatement pstmt = null, pstmt0 = null;
			
			
			
			
			
			
			
			//String CCParameterNameSearch = new String(request.getParameter("CCParameterNameSearch").getBytes("8859_1"),"utf-8");
			String CCParameterNameSearch = request.getParameter("CCParameterNameSearch");
			String StorerkeyFromSearch = request.getParameter("StorerkeyFromSearch");
		String StorerkeyToSearch = request.getParameter("StorerkeyToSearch");
		String SkuFromSearch = request.getParameter("SkuFromSearch");
		//String SkuToSearch = request.getParameter("SkuToSearch");
		String SkuToSearch = "";
		String ClassFromSearch = request.getParameter("ClassFromSearch");
		String ClassToSearch = request.getParameter("ClassToSearch");
		String ZoneFromSearch = request.getParameter("ZoneFromSearch");
		String ZoneToSearch = request.getParameter("ZoneToSearch");
		String LocFromSearch = request.getParameter("LocFromSearch");
		String LocToSearch = request.getParameter("LocToSearch");
		
		
		/***************debug*/
		
		System.out.println("CCParameterNameSearch:" + CCParameterNameSearch);
		System.out.println("StorerkeyFromSearch:" + StorerkeyFromSearch);
		System.out.println("StorerkeyToSearch:" + StorerkeyToSearch);
		System.out.println("SkuFromSearch:" + SkuFromSearch);
		System.out.println("SkuToSearch:" + SkuToSearch);
		System.out.println("ClassFromSearch:" + ClassFromSearch);
		System.out.println("ClassToSearch:" + ClassToSearch);
		System.out.println("ZoneFromSearch:" + ZoneFromSearch);
		System.out.println("ZoneToSearch:" + ZoneToSearch);
		System.out.println("LocFromSearch:" + LocFromSearch);
		System.out.println("LocToSearch:" + LocToSearch);
		/****************/
		String CCParameterName_q ="";
		String StorerkeyFrom_q = "0";
		String StorerkeyTo_q = "ZZZZZZZZZZZZZZZ";
		String SkuFrom_q = "0";
		String SkuTo_q = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
		String ClassFrom_q = "0";
		String ClassTo_q = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
		String ZoneFrom_q = "0";
		String ZoneTo_q = "ZZZZZZZZZZ";
		String LocFrom_q = "0";
		String LocTo_q = "ZZZZZZZZZZ";

		/*
		if(StorerkeyFromSearch.trim() !="") StorerkeyFrom_q = StorerkeyFromSearch.trim();
		if( StorerkeyToSearch.trim() !="") StorerkeyTo_q = StorerkeyToSearch.trim();
		if( SkuFromSearch.trim() !="") SkuFrom_q = SkuFromSearch.trim();
		if( SkuToSearch.trim() !="") SkuTo_q = SkuToSearch.trim();
		if( ClassFromSearch.trim() !="") ClassFrom_q = ClassFromSearch.trim();
		if( ClassToSearch.trim() !="") ClassTo_q = ClassToSearch.trim();
		if( ZoneFromSearch.trim() !="") ZoneFrom_q = ZoneFromSearch.trim();
		if( ZoneToSearch.trim() !="") ZoneTo_q = ZoneToSearch.trim();
		if( LocFromSearch.trim() !="") LocFrom_q = LocFromSearch.trim();
		if( LocToSearch.trim() !="") LocTo_q = LocToSearch.trim();
		*/
		
		if((CCParameterNameSearch !="") && (CCParameterNameSearch != null)){
		CCParameterName_q = "%" + new String(CCParameterNameSearch.getBytes("8859_1"),"utf-8") + "%";
		}
		else{
			CCParameterName_q = "%%";
		}
		if((StorerkeyFromSearch !="") && (StorerkeyFromSearch != null)) StorerkeyFrom_q = StorerkeyFromSearch;
		if((StorerkeyToSearch !="") && (StorerkeyToSearch != null)) StorerkeyTo_q = StorerkeyToSearch;
		if((SkuFromSearch !="") && (SkuFromSearch != null)) SkuFrom_q = SkuFromSearch;
		if((SkuToSearch !="") && (SkuToSearch != null)) SkuTo_q = SkuToSearch;
		if((ClassFromSearch !="") && (ClassFromSearch != null)) ClassFrom_q = ClassFromSearch;
		if((ClassToSearch !="") && (ClassToSearch != null)) ClassTo_q = ClassToSearch;
		if((ZoneFromSearch !="") && (ZoneFromSearch != null)) ZoneFrom_q = ZoneFromSearch;
		if((ZoneToSearch !="") && (ZoneToSearch != null)) ZoneTo_q = ZoneToSearch;
		if((LocFromSearch !="") && (LocFromSearch != null)) LocFrom_q = LocFromSearch;
		if((LocToSearch !="") && (LocToSearch != null)) LocTo_q = LocToSearch;
  		
  		/***************debug*/
  		
		System.out.println("CCParameterName_q:" + CCParameterName_q);
		System.out.println("StorerkeyFrom_q:" + StorerkeyFrom_q);
		System.out.println("StorerkeyTo_q:" + StorerkeyTo_q);
		System.out.println("SkuFrom_q:" + SkuFrom_q);
		System.out.println("SkuTo_q:" + SkuTo_q);
		System.out.println("ClassFrom_q:" + ClassFrom_q);
		System.out.println("ClassTo_q:" + ClassTo_q);
		System.out.println("ZoneFrom_q:" + ZoneFrom_q);
		System.out.println("ZoneTo_q:" + ZoneTo_q);
		System.out.println("LocFrom_q:" + LocFrom_q);
		System.out.println("LocTo_q:" + LocTo_q);
		/****************/
    	
    	
    	
		if("ok".equals(request.getParameter("status"))){
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
	
			Context ctx = new InitialContext();
			DataSource ds = (DataSource) ctx.lookup("java:jdbc/WMPRD_WMWHSE1");
			conn = ds.getConnection();
			
			pagesql0 = "SELECT COUNT(*) FROM CCParameter where StorerkeyFrom >= ? and StorerkeyTo <= ? and SkuFrom >= ? and SkuTo <= ? and ClassFrom >= ? and ClassTo <= ? and ZoneFrom >= ? and ZoneTo <= ? and LocFrom >= ? and LocTo <= ?  and CCParameterName like ?";
			pstmt0 = conn.prepareStatement(pagesql0);
			
	    	pstmt0.setString(	1	 ,	StorerkeyFrom_q	);
			pstmt0.setString(	2	 ,	StorerkeyTo_q	);
			pstmt0.setString(	3	 ,	SkuFrom_q	);
			pstmt0.setString(	4	 ,	SkuTo_q	);
			pstmt0.setString(	5	 ,	ClassFrom_q	);
			pstmt0.setString(	6	 ,	ClassTo_q	);
			pstmt0.setString(	7	 ,	ZoneFrom_q	);
			pstmt0.setString(	8	 ,	ZoneTo_q	);
			pstmt0.setString(	9	 ,	LocFrom_q	);
			pstmt0.setString(	10	 ,	LocTo_q	);
			pstmt0.setString(	11	 ,	CCParameterName_q	);
			
			pagers0 = pstmt0.executeQuery();

			while (pagers0.next()) {
				allCol = pagers0.getInt(1);
				/****************debug*/
				System.out.println(allCol);
				/*****************/
			}
			//獲得總頁面數 
			allpage = (int) Math.ceil((allCol + ipage - 1) / ipage);
			//判斷參數pages是否空 
			if (request.getParameter("pages") == null) {
				pages = 1;
			} else {
				pages = new Integer(request.getParameter("pages")).intValue();
				System.out.println(pages);
			}
			
			/****************debug*/
			System.out.println("pages: " + pages);
			/*****************/
			
			//判斷當前頁 
			if (pages > allpage || pages == 0 || pages ==1) {
				cpage = 1;
				%><a href="javascript:alert('已經是第一頁');"><img name = "pic1" src="../image/matrixbutton_first_d.gif" width="15" height="15" border="0" alt="第一頁"></a>
				<a href="JavaScript:alert('已經是第一頁');"><img name = "pic2" src="../image/matrixbutton_previous_d.gif" width="15" height="15" border="0" alt="上一頁"></a>
				
				<%
				
			} else {
				cpage = pages;
				%>
				<a href="JavaScript:Go_Page(1);"><img name = "pic1" src="../image/matrixbutton_first.gif" width="15" height="15" border="0" alt="第一頁"></a>
				<a href="JavaScript:Go_Page(<%=pages-1 %>);"><img name = "pic2" src="../image/matrixbutton_previous.gif" width="15" height="15" border="0" alt="上一頁"></a>

				<%
			}
			
			if ( cpage < allpage) {
				/****************debug*/
				System.out.println("test1");
				/*****************/
				%>
				<a href="JavaScript:Go_Page(<%=pages+1 %>);"><img name = "pic3" src="../image/matrixbutton_next.gif" width="15" height="15" border="0" alt="下一頁"></a>
				<a href="JavaScript:Go_Page(<%=allpage %>);"><img name = "pic4" src="../image/matrixbutton_last.gif" width="15" height="15" border="0" alt="最後一頁"></a>
				<%
			}
			if (cpage == allpage) {
				/****************debug*/
				System.out.println("test2");
				/*****************/
				%>
				<a href="JavaScript:alert('已經是最後一頁');""><img name = "pic3" src="../image/matrixbutton_next_d.gif" width="15" height="15" border="0" alt="下一頁"></a>
				<a href="JavaScript:alert('已經是最後一頁');""><img name = "pic4" src="../image/matrixbutton_last_d.gif" width="15" height="15" border="0" alt="最後一頁"></a>
				<%
			}
			%>
			<select id="pages" name="pages" onChange="JavaScript:Go_Page(this.value)">
			<%
			for (i = 1; i <= allpage; i++) {
				%>
				
				<option value="<%=i%>"
					
					<% if(i==cpage){
							%>selected<%
					}
					%>
					>
					<%=i%>
					</option>
				
				<%
			}
			%> 
			</select>
			
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% out.print(status); %>
			</div>
			</div>
			</tr>
			<%
			} catch (Exception sqle) {
				//out.println(" Exception : " + sqle.getMessage());
				sqle.printStackTrace();
				System.out.println(" Exception : " + sqle.getMessage());
			}
			finally {
		        if (conn != null){
		        	conn.close();
		        }
			}
		}
			%>
			
		</table>
		
		<table id="mytable" width="100%" border = 1 ALIGN="CENTER" class="gridBody">
			<tr>
				<th style="width: 10px;">&nbsp;</th>
				<th style="width: 10px;"><img onclick="Search()" src="../icon/zoom.jpg" width="20" height="20" alt="search" /></th>
				<th style="width: 70px;"><input size="7" type="text" name="CCParameterNameSearch" id="CCParameterNameSearch" value="<%=request.getParameter("CCParameterNameSearch")==null?"":new String(request.getParameter("CCParameterNameSearch").getBytes("8859_1"),"utf-8")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="StorerkeyFromSearch" id="StorerkeyFromSearch" value="<%=request.getParameter("StorerkeyFromSearch")==null?"":request.getParameter("StorerkeyFromSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="StorerkeyToSearch" id="StorerkeyToSearch" value="<%=request.getParameter("StorerkeyToSearch")==null?"":request.getParameter("StorerkeyToSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="SkuFromSearch" id="SkuFromSearch" value="<%=request.getParameter("SkuFromSearch")==null?"":request.getParameter("SkuFromSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="SkuToSearch" name="SkuToSearch" value="<%=request.getParameter("SkuToSearch")==null?"":request.getParameter("SkuToSearch")%>" /></th>
				<th style="width: 70px;"><input size="7" type="text" name="ClassFromSearch" id="ClassFromSearch" value="<%=request.getParameter("ClassFromSearch")==null?"":request.getParameter("ClassFromSearch")%>" /></th>
				<th style="width: 70px;"><input size="7" type="text" name="ClassToSearch" id="ClassToSearch" value="<%=request.getParameter("ClassToSearch")==null?"":request.getParameter("ClassToSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="ZoneFromSearch" id="ZoneFromSearch" value="<%=request.getParameter("ZoneFromSearch")==null?"":request.getParameter("ZoneFromSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="ZoneToSearch" id="ZoneToSearch" value="<%=request.getParameter("ZoneToSearch")==null?"":request.getParameter("ZoneToSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="LocFromSearch" id="LocFromSearch" value="<%=request.getParameter("LocFromSearch")==null?"":request.getParameter("LocFromSearch")%>" /></th>
				<th style="width: 40px;"><input size="7" type="text" name="LocToSearch" id="LocToSearch" value="<%=request.getParameter("LocToSearch")==null?"":request.getParameter("LocToSearch")%>" /></th>
			</tr>
			<tr>
				<th Width="10">&nbsp;</th>
				<th Width="10">&nbsp;</th>
				<th style="width: 70px;">名稱</th>
				<th style="width: 40px;">貨主起</th>
				<th style="width: 40px;">貨主迄</th>
				<th style="width: 40px;">貨品起</th>
				<th style="width: 40px;">貨品迄</th>
				<th style="width: 70px;">品類大項起</th>
				<th style="width: 70px;">品類大項迄</th>
				<th style="width: 40px;">區起</th>
				<th style="width: 40px;">區迄</th>
				<th style="width: 40px;">儲位起</th>
				<th style="width: 40px;">儲位迄</th>
			</tr>
			
			<%
			if("ok".equals(request.getParameter("status"))){
			try {
				
			Class.forName("oracle.jdbc.driver.OracleDriver");
	
			Context ctx = new InitialContext();
			DataSource ds = (DataSource) ctx.lookup("java:jdbc/WMPRD_WMWHSE1");
			conn = ds.getConnection();
			//判斷起始頁 
			String sql = "select Top "
				+ ipage
				+ " Serailkey, CCParameterName, StorerkeyFrom, StorerkeyTo , SkuFrom, SkuTo, ClassFrom, ClassTo, ZoneFrom, ZoneTo, LocFrom, LocTo, XCOORDFROM, XCOORDTO, YCOORDFROM, YCOORDTO, ZCOORDFROM, ZCOORDTO, DisplaySystemCount "
				+ " FROM CCParameter where StorerkeyFrom >= ? and StorerkeyTo <= ? and SkuFrom >= ? and SkuTo <= ? and ClassFrom >= ? and ClassTo <= ? and ZoneFrom >= ? and ZoneTo <= ? and LocFrom >= ? and LocTo <= ?  and CCParameterName like ? "
				+ " and Serailkey not in (select top "
				+ (cpage - 1) * ipage
				+ " Serailkey FROM CCParameter where StorerkeyFrom >= ? and StorerkeyTo <= ? and SkuFrom >= ? and SkuTo <= ? and ClassFrom >= ? and ClassTo <= ? and ZoneFrom >= ? and ZoneTo <= ? and LocFrom >= ? and LocTo <= ?  and CCParameterName like ? "
				+ " order by Serailkey desc ) order by Serailkey desc ";
				
			/****************debug*/
			System.out.println("sql: " + sql);
			/*****************/
			
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(	1	 ,	StorerkeyFrom_q	);
			pstmt.setString(	2	 ,	StorerkeyTo_q	);
			pstmt.setString(	3	 ,	SkuFrom_q	);
			pstmt.setString(	4	 ,	SkuTo_q	);
			pstmt.setString(	5	 ,	ClassFrom_q	);
			pstmt.setString(	6	 ,	ClassTo_q	);
			pstmt.setString(	7	 ,	ZoneFrom_q	);
			pstmt.setString(	8	 ,	ZoneTo_q	);
			pstmt.setString(	9	 ,	LocFrom_q	);
			pstmt.setString(	10	 ,	LocTo_q	);
			pstmt.setString(	11	 ,	CCParameterName_q	);
			
			pstmt.setString(	12	 ,	StorerkeyFrom_q	);
			pstmt.setString(	13	 ,	StorerkeyTo_q	);
			pstmt.setString(	14	 ,	SkuFrom_q	);
			pstmt.setString(	15	 ,	SkuTo_q	);
			pstmt.setString(	16	 ,	ClassFrom_q	);
			pstmt.setString(	17	 ,	ClassTo_q	);
			pstmt.setString(	18	 ,	ZoneFrom_q	);
			pstmt.setString(	19	 ,	ZoneTo_q	);
			pstmt.setString(	20	 ,	LocFrom_q	);
			pstmt.setString(	21	 ,	LocTo_q	);
			pstmt.setString(	22	 ,	CCParameterName_q	);
			
			ResultSet rs = pstmt.executeQuery();
			boolean firstrecord = true;
			/****************debug*/
			System.out.println("sql sucess");
			/*****************/
			
			while (rs.next()){
    	
				////<td><input type="image" onclick="Search()" src="../icon/zoom.jpg" width="20" height="20" alt="<%=rs.getString("Serailkey")
				%>
				<tr>
				<th style="width: 10px;"><input type="checkbox" name="item" value="<%=rs.getString("Serailkey")%>" /><br /></th>
				<th style="width: 10px;"><img class="detailImg" src="../icon/icon_detail.gif" id="<%=rs.getString("Serailkey")%>" value="<%=rs.getString("Serailkey")%>" alt="<%=rs.getString("Serailkey")%>"></img></th>
				<td style="width: 100px;"><%=rs.getString("CCParameterName") %></td>
				<td style="width: 40px;"><%=rs.getString("StorerkeyFrom") %></td>
				<td style="width: 40px;"><%=rs.getString("StorerkeyTo") %></td>
				<td style="width: 40px;"><%=rs.getString("SkuFrom") %></td>
				<td style="width: 40px;"><%=rs.getString("SkuTo") %></td>
				<td style="width: 40px;"><%=rs.getString("ClassFrom") %></td>
				<td style="width: 40px;"><%=rs.getString("ClassTo") %></td>
				<td style="width: 40px;"><%=rs.getString("ZoneFrom") %></td>
				<td style="width: 40px;"><%=rs.getString("ZoneTo") %></td>
				<td style="width: 40px;"><%=rs.getString("LocFrom") %></td>
				<td style="width: 40px;"><%=rs.getString("LocTo") %></td>
				</tr>
				<%
				}
			} catch (Exception sqle) {
				//out.println(" Exception : " + sqle.getMessage());
				sqle.printStackTrace();
				System.out.println(" Exception : " + sqle.getMessage());
			}
			finally {
		        if (conn != null){
		        	conn.close();
		        }
			}
		}
			%>
			
			
		</table>
		<BR />
		<BR />
		
		
		<table id="detail" border=0 ALIGN="CENTER" RULES=NONE FRAME=BOX class="gridBody">
			<tr>
				<th Width="150" COLSPAN=2>循環盤點參數名稱</th>
				<th Width="70" COLSPAN=2><input id="CCParameterName" type="text" name="CCParameterName" /></th>
				<input id="Serailkey" type="hidden" name="Serailkey" />
				
			</tr>
			<tr>
				<th Width="70"></th>
				<th Width="70">起</th>
				<th Width="70">迄</th>
				<th Width="120" ROWSPAN=6 >
					<div id="submit">
					請選擇盤點模式：<br />
					<input type="radio" id = "CC" name="type" value="CC" />循環盤點<br />
					<input type="radio" name="type" value="ITRN" />異動盤點<br />
					<input type="radio" name="type" value="EMPTY" />空庫位盤點<br />
					<br />
					<input type="submit" class="wmsButton" value="發佈" />
					</div>
				</th>
			</tr>
			<tr>
				<th Width="70">貨主</th>
				<th Width="70"><input id="StorerkeyFrom" type="text" name="StorerkeyFrom" /></th>
				<th Width="70"><input id="StorerkeyTo" type="text" name="StorerkeyTo" /></th>
				
			</tr>
			<tr>
				<th Width="70">貨品</th>
				<th Width="70"><input id="SkuFrom" type="text" name="SkuFrom" /></th>
				<th Width="70"><input id="SkuTo" type="text" name="SkuTo" /></th>
			</tr>
			<tr>
				<th Width="70">品類大項</th>
				<th Width="70"><input id="ClassFrom" type="text" name="ClassFrom" /></th>
				<th Width="70"><input id="ClassTo" type="text" name="ClassTo" /></th>
			</tr>
			<tr>
				<th Width="70">區</th>
				<th Width="70"><input id="ZoneFrom" type="text" name="ZoneFrom" /></th>
				<th Width="70"><input id="ZoneTo" type="text" name="ZoneTo" /></th>
			</tr>
			<tr>
				<th Width="70">儲位</th>
				<th Width="70"><input id="LocFrom" type="text" name="LocFrom" /></th>
				<th Width="70" ><input id="LocTo" type="text" name="LocTo" /></th>
			</tr>
			<tr>
				<th Width="70">X坐標</th>
				<th Width="70"><input id="XCOORDFROM" type="text" name="XCOORDFROM" /></th>
				<th Width="70" COLSPAN =2><input id="XCOORDTO" type="text" name="XCOORDTO" /></th>
			</tr>
			<tr>
				<th Width="70">Y坐標</th>
				<th Width="70"><input id="YCOORDFROM" type="text" name="YCOORDFROM" /></th>
				<th Width="70" COLSPAN =2><input id="YCOORDTO" type="text" name="YCOORDTO" /></th>
			</tr>
			<tr>
				<th Width="70">Z坐標</th>
				<th Width="70"><input id="ZCOORDFROM" type="text" name="ZCOORDFROM" /></th>
				<th Width="70" COLSPAN =2><input id="ZCOORDTO" type="text" name="ZCOORDTO" /></th>
			</tr>
		<tr><th Width="70">顯示系統量<br /></th>
		<th Width="70" COLSPAN =3><input type="checkbox" id ="DisplaySystemCount" name="DisplaySystemCount" value="1" /></th>
		</tr>
		</table>
	</form>
</body>
</html>

